package com.aopcinemas.visitor.behaviour;

import jade.content.lang.Codec.CodecException;
import jade.content.onto.OntologyException;
import jade.content.onto.basic.Action;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;
import jade.proto.AchieveREInitiator;

import com.aopcinemas.visitor.VisitorAgent;
import com.aopcinemas.visitor.ontology.GetCampaign;

public class CampaignInfoInitiator extends AchieveREInitiator {

    private static final long serialVersionUID = 1L;

    public CampaignInfoInitiator(Agent a, ACLMessage msg) {
        super(a, msg);
    }

    @Override
    protected void handleInform(ACLMessage inform) {
        try {
            VisitorAgent agent = (VisitorAgent) myAgent;
            Action action = (Action) agent.getContentManager().extractContent(inform);
            GetCampaign getCampaign = (GetCampaign) action.getAction();
            System.out.println("Hei, campaign received: " + getCampaign.getCampaign().getSchedule().getMovie().getName() + " , " + getCampaign.getCampaign().getType().toString());
            agent.notifyCampaign(getCampaign);
        } catch (CodecException e) {
            e.printStackTrace();
        } catch (OntologyException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void handleRefuse(ACLMessage refuse) {
        System.out.println("Hei, campaign refused!");
    }

    @Override
    protected void handleFailure(ACLMessage failure) {
        System.out.println("Hei, failure!");
    }

    @Override
    protected void handleInconsistentFSM(String current, int event) {
        System.out.println("Hei, inconsisten!");
    }

}
